package cn.kgc.kongqi.service;

import cn.kgc.kongqi.mapper.IndexMapper;
import cn.kgc.kongqi.pojo.Index;
import cn.kgc.kongqi.pojo.IndexExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 * @create 2020-05-20 22:27
 */
@Service
public class IndexServiceImpl implements  IndexService{

    @Resource
    IndexMapper indexMapper;
    @Override
    public PageInfo<Index> selectPageInfo(Integer pageNum, Integer pageSize, Integer districtId) {
        PageHelper.startPage(pageNum,pageSize);

        IndexExample example=new IndexExample();
        IndexExample.Criteria criteria = example.createCriteria();

        if(districtId==0){
            List<Index> indices = indexMapper.selectByExample(null);
            PageInfo<Index> pageInfo=new PageInfo<>(indices);
            return pageInfo;
        }else{
            criteria.andDistrictidEqualTo(districtId);
            List<Index> indices = indexMapper.selectByExample(example);
            PageInfo<Index> pageInfo=new PageInfo<>(indices);
            return pageInfo;
        }
    }

    @Override
    public Integer addIndex(Index index) {
        return indexMapper.insert(index);
    }

    @Override
    public Integer deleteIndex(Integer id) {
        return indexMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Index indexById(Integer id) {
        return indexMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer updateIndex(Index index) {
        return indexMapper.updateByPrimaryKeySelective(index);
    }
}
